import java.sql.SQLException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Combo;

//Test
public class removefriend extends Dialog {

        protected Object result;
        protected Shell shell;
  protected ClientLogic logic;

        /**
         * Create the dialog.
         * @param parent
         * @param style
         */
        public removefriend(Shell parent, int style) {
                super(parent, style);
                setText("Remove Friend");
      logic = new ClientLogic();
        }

        /**
         * Open the dialog.
         * @return the result
         */
        public Object open() {
                createContents();
                shell.open();
                shell.layout();
                Display display = getParent().getDisplay();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                return result;
        }

        /**
         * Create contents of the dialog.
         */
        private void createContents() {
                shell = new Shell(getParent(), getStyle());
                shell.setSize(346, 168);
                shell.setText(getText());
                
                Label lblUserName = new Label(shell, SWT.NONE);
                lblUserName.setBounds(10, 42, 85, 27);
                lblUserName.setText("User Name:");
                
                final Combo DropDown = new Combo(shell, SWT.DROP_DOWN | SWT.BORDER);
                DropDown.setBounds(101, 40, 189, 29);

                
                final Label resultLabel = new Label(shell, SWT.NONE);
                resultLabel.setBounds(101, 69, 233, 17);
                resultLabel.setVisible(false);
                
                Button btnAdd = new Button(shell, SWT.NONE);
                btnAdd.setBounds(10, 99, 91, 29);
                btnAdd.setText("Remove");
                btnAdd.addListener(SWT.Selection, new Listener() {
                                public void handleEvent(org.eclipse.swt.widgets.Event event) 
                                {
                                    String newFriend = DropDown.getItem(DropDown.getSelectionIndex());
                                    try {
										logic.removeFriend(newFriend);
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
                                    resultLabel.setText(newFriend + " has been removed from your Friend's List.");
                                
                        resultLabel.setVisible(true);
                        }
                });
                
                Button btnCancel = new Button(shell, SWT.NONE);
                btnCancel.setBounds(243, 99, 91, 29);
                btnCancel.setText("Cancel");
                btnCancel.addListener(SWT.Selection, new Listener() {
                        public void handleEvent(org.eclipse.swt.widgets.Event event) {
                                shell.close();
                        }
                });

        }
}